<?php

function reequipment_adminapi_createmodels($args)
{
    extract($args);

    // Argument check - make sure that all required arguments are present,
    // if not then set an appropriate error message and return
    $invalid = array();
    if (!isset($model_name) || !is_string($model_name)) {
        $invalid[] = 'model_name';
    } 
   	if (!isset($area_id) || !is_int($area_id)) {
        $invalid[] = 'area_id';
    } 
    if (!isset($current) || !is_bool($current)) {
        $invalid[] = 'current';
    } 
    if (count($invalid) > 0) {
        $msg = xarML('Invalid #(1)', join(', ', $invalid));
        xarErrorSet(XAR_SYSTEM_EXCEPTION, 'BAD_PARAM', new SystemException($msg));
        return;
    } 
    
    // Get datbase setup
    $dbconn =& xarDBGetConn();
    $xartable =& xarDBGetTables();
    $table = $xartable['remodels'];
    // Get next ID in table
    $nextId = $dbconn->GenId($table);

    // Add item
    $query = "INSERT INTO $table ("
        . " model_id, area_id, model_name, current )"
        . " VALUES (?, ?, ?, ?)";
    $result =& $dbconn->Execute($query, array($nextId, $area_id, $model_name, $current));
    if (!$result) return;
    // Get the ID of the item that we inserted
    $id = $dbconn->PO_Insert_ID($table, 'model_id');

    // Let any hooks know that we have created a new forum
    $args['module'] = 'reequipment';
    $args['itemtype'] = 2; // post
    $args['itemid'] = $id; // post
    xarModCallHooks('item', 'create', $id, $args);// post
    // Return the id of the newly created link to the calling process
    return $id;
}
?>